<?php
namespace Article\Model;

class ArticleModel extends \Common\Model\BaseModel{
	
	protected $tableName = "article";

	protected $_validate = array(
		array('title','require','标题必填',1),
		array('content','require','文章必填',1),
	);

	protected $_auto = array(
        array('title', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
        array('title', 'require', '标题不能为空', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
        array('title', '1,100', '标题长度不能超过80个字符', self::MUST_VALIDATE, 'length', self::MODEL_BOTH),
		
        array('content', 'htmlspecialchars_decode', self::MODEL_BOTH, 'function'),
		array('addtime','time',1,'function'),
		array('updatetime','time',3,'function'),
	);

	public function getRecomment($cateid,$limit){
		if ($cateid) {
			$map['cateid'] = $cateid;
		}
		$map['isrecommend'] = 1;

		$data = $this->where($map)->order('addtime desc')->limit($limit)->select();
		foreach ($data as $key => $value) {
			if ($value['photo']) {
				$data[$key]['photo'] = $value['photo'];
			}else{
				$data[$key]['photo'] = './Public/Static/images/dot.png';
			}
			$data[$key]['instro'] = msubstr(tt($value['content']),0,35);
		}
		return $data;
	}
}